package com.amat0urheu.dao;

import com.amat0urheu.pojo.Team;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface TeamMapper {
    @Select("select * from  mc_team order by  tscore desc")
    List<Team> selectAllTeam();
    @Select("update  mc_team set tscore =tscore+#{tscore} where tname=#{tname}")
    String addScore(String tname,Integer tscore);
    @Select("select count(*) from mc_user where teamname=#{tname}")
    Integer findNumOfTeam(String tname);
    @Update("update mc_team set peopleNum=peopleNum+1 where tname=#{tname}")
    void updateTeamNum(String tname);

    @Update("update mc_team set peopleNum=peopleNum-1 where tname=#{tname}")
    void reduceNum(String teamName);
@Select("select count(*) from mc_user where teamName=#{tname} ")
    int getCountOfPeo(String tname);

    @Select("select uname from mc_user where teamName=#{tname} ")
    List<String> getPeoOfTeam(String tname);
    @Select("select count(*) from mc_team where tcaptain=#{name}")
    int judgeIsTcaptain(String name);
    @Select("select teamname from mc_user where uname=#{name}")
    String getTeamName(String name);

    @Select("select tcaptain from mc_team where tname=#{teamName}")
    String getTcaptain(String teamName);

    @Select("select count(*) from     mc_race_current_ranking where rid=#{rid}")
    Integer getTeanCount(Integer rid);
    @Select("select * from  mc_team  where  ${key} like #{value}")
    List<Team> searchRaceByPageforAdmin(String key, String value);
    @Select("select count(*)  from     mc_team where  tname=#{teamName}")
    Integer hasTeam(String teamName);
    @Update("update mc_team set tcaptain=#{user} where tname=#{teamName}")
    void updateCaptainofTeam(String teamName,String user);
@Insert("insert into mc_team (tname,tcaptain) values(#{teamName},#{user})")
    void addTeam(String teamName,String user);
}